package com.dhu.stylefit.service;

import com.dhu.stylefit.model.Recommendation;
import com.dhu.stylefit.repository.RecommendationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class RecommendationService {

    @Autowired
    private RecommendationRepository recommendationRepository;

    public Map<String, List<Recommendation>> getRecommendationsByUserId(Integer userId) {
        List<Recommendation> recommendations = recommendationRepository.findByUserIdOrderBySimilarityDesc(userId);
        
        // 按类别分组并按相似度排序
        return recommendations.stream()
                .collect(Collectors.groupingBy(
                    Recommendation::getCategory,
                    Collectors.collectingAndThen(
                        Collectors.toList(),
                        list -> list.stream()
                                .sorted((r1, r2) -> Float.compare(r2.getSimilarity(), r1.getSimilarity()))
                                .collect(Collectors.toList())
                    )
                ));
    }
} 